/*
 *   Copyright (C) 2008 - 2009  FireBalls
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

// includes
#include "Sound.h"

Sound *sound;

int Sound::Init() {

    if(Mix_OpenAudio(SoundFrequency, MIX_DEFAULT_FORMAT, SoundChannels, 1024) < 0) {
        return -1;
    }

    Mix_Volume(-1, SoundVolume);

    return 0;
}

Mix_Chunk* Sound::Load(string path) {

    Mix_Chunk *sound;

    sound = Mix_LoadWAV(path.c_str());

    if(sound == NULL) {
        Log_Errors.Write(Mix_GetError());
        Log_Errors.Endl();
    }

    return sound;
}

void Sound::Play(Mix_Chunk *sound) {
    Mix_PlayChannel(-1, sound, 0);
}

void Sound::Volume(int i) {
    Mix_Volume(-1, i);
}
